package com.demo2do.fms.entity.authority;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import com.demo2do.core.format.PersistentFormat;

/**
 * 用户
 * 
 * @author Ysy
 *
 */
@Entity
@Table(name = "TBL_ALL_USER_INFO")
@PersistentFormat
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 登录名  */
    private String loginName;
    
    /** 密码  */
    private String password;
    
    /** 角色 ：使用code关联*/
    @Column(name = "role_code")
    private String authority;
    
    /** 分区：分区用户所属分区, 使用code关联  */
    @Column(name = "branch_code")
    private String branch;
    
    /** 服务供应商：一级/二级供应商用户所属供应商， 对应Supplier  */
    private Long supplierId;
    
    /** 运输业务供应商：运输业务供应商用户所属供应商， 对应TransportationCompany */
    private Long orgId;
    
    /** 姓名  */
    private String name;
    
    /** 性别  */
    private String gender;
    
    /** 联系地址  */
    private String address;
    
    /** 创建人  */
    private Long creator;
    
    /** 创建时间  */
    @Column(name = "create_date")
    private Date createTime;
    
    /** 最后操作人  */
    private Long lastOperator;
    
    /** 最后修改时间  */
    @Column(name = "last_modify_date")
    private Date lastModifyTime;
    
    @Column(name = "is_fms_plus")
    private Boolean fmsPlus;
    
    /** 老系统独有字段：邮政编码*/
    private String zipCode;
    
    /** 老系统独有字段 */
    private Long roleId;
    
    /** 是否启用  */
    @Column(name = "is_disabled")
    private Boolean disabled;
    
    // ===== VAM新增字段 ====
    
    /** 座机号码 */
    private String phone;
    
    /** 手机号码 */
    private String mobile;
    
    /** 电子邮箱 */
    private String email;
    
    /** 所属部门 */
    private Long departmentId;
    
    /** 所属部门名称 */
    private String departmentName;
    
    /** 是否VAM供方用户 */
    @Column(name = "is_vam")
    private boolean vam;

    /**
     * the default constructor
     */
    public User() {
    }
    
    /**
     * @param creator
     * @return
     */
    public User initialize(Long creator) {
        this.password = DigestUtils.md5Hex(this.password);
        this.fmsPlus = true;
        this.creator = creator;
        this.createTime = new Date();
        this.lastOperator = creator;
        this.lastModifyTime = new Date();
        this.disabled = false;
        return this;
    }
    
    /**
     * @param orgId
     * @return
     */
    public User editVam(Long orgId) {
        this.vam = true;
        this.orgId = orgId;
        return this;
    }
    
    /**
     * @param operator
     * @param now
     * @return
     */
    public User operator(Long operator, Date now) {
    	this.lastOperator = operator;
    	this.lastModifyTime = now;
    	return this;
    }
    
    /**
     * 
     * @return
     */
    public User disable(){
        this.disabled = true;
        return this;
    }
    
    /**
     * 
     * @param password
     * @return
     */
    public User resetPassword(String password){
        this.password = DigestUtils.md5Hex(password);
        return this;
    }
    
    /**
     * @param password
     * @return
     */
    public User editPassword(String password) {
        this.password = DigestUtils.md5Hex(password);
        return this;
    }
    
    /**
     * @param existPassword
     * @return
     */
    public boolean checkExistPassword(String existPassword) {
        return StringUtils.equals(this.password, DigestUtils.md5Hex(existPassword));
    }
    
    /**
     * 
     * @param supplierId
     * @return
     */
    public User initSupplierId(Long supplierId){
        this.supplierId = supplierId;
        return this;
    }
    
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the loginName
	 */
	public String getLoginName() {
		return loginName;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @return the authority
	 */
	public String getAuthority() {
		return authority;
	}

	/**
	 * @return the branch
	 */
	public String getBranch() {
		return branch;
	}

	/**
	 * @return the supplierId
	 */
	public Long getSupplierId() {
		return supplierId;
	}

	/**
	 * @return the orgId
	 */
	public Long getOrgId() {
		return orgId;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the gender
	 */
	public String getGender() {
		return gender;
	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * @return the creator
	 */
	public Long getCreator() {
		return creator;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @return the lastOperator
	 */
	public Long getLastOperator() {
		return lastOperator;
	}

	/**
	 * @return the lastModifyTime
	 */
	public Date getLastModifyTime() {
		return lastModifyTime;
	}
	
	/**
     * @return the fmsPlus
     */
    public Boolean getFmsPlus() {
        return fmsPlus;
    }

    /**
     * @return the zipCode
     */
    public String getZipCode() {
        return zipCode;
    }

    /**
     * @return the roleId
     */
    public Long getRoleId() {
        return roleId;
    }

	/**
	 * @return the disabled
	 */
	public Boolean getDisabled() {
		return disabled;
	}
	
	/**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @return
     */
    public Long getDepartmentId() {
        return departmentId;
    }
    
    /**
     * @return
     */
    public String getDepartmentName() {
        return departmentName;
    }

    /**
     * @return
     */
    public boolean isVam() {
        return vam;
    }

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param loginName the loginName to set
	 */
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @param authority the authority to set
	 */
	public void setAuthority(String authority) {
		this.authority = authority;
	}

	/**
	 * @param branch the branch to set
	 */
	public void setBranch(String branch) {
		this.branch = branch;
	}

	/**
	 * @param supplierId the supplierId to set
	 */
	public void setSupplierId(Long supplierId) {
		this.supplierId = supplierId;
	}

	/**
	 * @param orgId the orgId to set
	 */
	public void setOrgId(Long orgId) {
		this.orgId = orgId;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param gender the gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @param creator the creator to set
	 */
	public void setCreator(Long creator) {
		this.creator = creator;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @param lastOperator the lastOperator to set
	 */
	public void setLastOperator(Long lastOperator) {
		this.lastOperator = lastOperator;
	}

	/**
	 * @param lastModifyTime the lastModifyTime to set
	 */
	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	/**
	 * @param fmsPlus the fmsPlus to set
	 */
	public void setFmsPlus(Boolean fmsPlus) {
		this.fmsPlus = fmsPlus;
	}

	/**
	 * @param zipCode the zipCode to set
	 */
	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	/**
	 * @param roleId the roleId to set
	 */
	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}
	
	/**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @param departmentId
     */
    public void setDepartmentId(Long departmentId) {
        this.departmentId = departmentId;
    }
    
    /**
     * @param departmentName
     */
    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    
    /**
     * @param vam
     */
    public void setVam(boolean vam) {
        this.vam = vam;
    }

}
